//
//  PicViewController.m
//  小胖兔旅游指南
//
//  Created by 小胖兔 on 15/4/15.
//  Copyright (c) 2015年 小胖兔. All rights reserved.
//

#import "PicViewController.h"
#import "EScrollerView.h"

@interface PicViewController ()<EScrollerViewDelegate>

@end

@implementation PicViewController

- (void)dealloc
{
    [_PicArray release];
    [_eScroller release];
    [_contentArray release];
    [_contentScroll release];
    [_contentLabel release];
    
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.PicArray = [NSMutableArray array];
        self.contentArray = [NSMutableArray array];
         
    }
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor blackColor]];
    [self.navigationController.navigationBar setTranslucent:NO];
    [self.navigationController.navigationBar setBarTintColor:[UIColor blackColor]];
    [self.navigationController.navigationBar setAlpha:1.0];
    [self createView];
}

- (void)createView
{
    self.eScroller = [[EScrollerView alloc] initWithFrameRect:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height / 5, [[UIScreen mainScreen] bounds].size.width, ([[UIScreen mainScreen] bounds].size.width / 998.0 * 554.0)) ImageArray:self.PicArray TitleArray:nil];
    [self.view addSubview:self.eScroller];
    [self.eScroller setDelegate:self];
    [self.eScroller release];
    [self.eScroller.scrollView setContentOffset:CGPointMake(self.pageNum * self.eScroller.frame.size.width, 0)];
    
   

    self.contentScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.eScroller.frame.origin.y +self.eScroller.frame.size.height, [[UIScreen mainScreen] bounds].size.width, 120)];
    [self.view addSubview:self.contentScroll];
    self.contentLabel = [[UILabel alloc] init];
    [self.contentScroll addSubview:self.contentLabel];
    [self.contentLabel release];
    [self.contentLabel setNumberOfLines:0];
    [self.contentLabel setFont:[UIFont systemFontOfSize:16]];
    [self.contentLabel setTextColor:[UIColor whiteColor]];
    [self.contentLabel setTextAlignment:NSTextAlignmentLeft];
    
    NSString *content = [self.contentArray objectAtIndex:self.eScroller.pageControl.currentPage];
    content = [content stringByReplacingOccurrencesOfString:@"<br />" withString:@""];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:[UIFont systemFontOfSize:16] forKey:NSFontAttributeName];
    CGRect rect = [content boundingRectWithSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width - 30, 1000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    [self.contentLabel setFrame:CGRectMake(15, 0, self.contentScroll.frame.size.width - 30, rect.size.height)];
    [self.contentLabel setText:content];
    [self.contentScroll addSubview:self.contentLabel];
    [self.contentScroll setContentSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width, self.contentLabel.frame.size.height)];
    
    
}

-(void)EScrollerViewDidPageChange:(NSUInteger)index
{
    NSString *content = [self.contentArray objectAtIndex:index];
    content = [content stringByReplacingOccurrencesOfString:@"<br />" withString:@"\n"];

    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:[UIFont systemFontOfSize:16] forKey:NSFontAttributeName];
    CGRect rect = [content boundingRectWithSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width - 30, 1000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    [self.contentLabel setFrame:CGRectMake(15, 0, self.contentScroll.frame.size.width - 30, rect.size.height)];
    [self.contentLabel setText:content];
    [self.contentScroll addSubview:self.contentLabel];
    [self.contentScroll setContentSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width, self.contentLabel.frame.size.height)];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
